package com.sky.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    // 确保路径以斜杠结尾
    @Value("${file.storage.path}")
    private String storagePath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 确保路径以斜杠结尾
        String normalizedPath = storagePath.endsWith("/") ? storagePath : storagePath + "/";

        registry.addResourceHandler("/uploads/**")
                .addResourceLocations("file:" + normalizedPath);
    }
}